package com.plant.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.plant.dao.BaseDao;
import com.plant.entity.PgcTopic;
import com.plant.service.TopicService;

/**
 *
 * @author 植物先生-李琦
 * 			---下面是
 * 
 * 
 */
@Service  //依赖注册 必须写注册 下面在写resource资源
@Transactional
public class TopicServiceImpl implements TopicService{
    @Resource(name = "baseDaoImpl")//注解扫描basedao接口方法
    private BaseDao baseDao;

	public boolean addtopic(PgcTopic pt) {	//新建话题实现方法
		boolean isadd=true; 
		isadd=baseDao.add(pt);
		return isadd;
	}
	public boolean uptopic(PgcTopic pt) {	//修改话题实现方法
		boolean isadd=true; 
		isadd=baseDao.update(pt);
		return isadd;
	}
	public boolean deltopic(PgcTopic pt) {	//删除话题实现方法
		boolean isadd=true; 
		isadd=baseDao.del(pt);
		return isadd;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> listtopic(PgcTopic pa,Integer page,String time) {//显示一个马甲用户的话题
		List<Object> list3=new ArrayList<Object>();
        System.out.println("你好我是时间"+time);
    	String hql="select a.id,a.title,a.create_time,b.nickname,b.photo from pgc_topic as a,ugc_user as b where a.user_id=("+pa.getUserId()+") and a.user_id=b.id and a.create_time<? order by a.create_time desc";//--通过 时间分页查询 显示10条
        list3=baseDao.findfenye((page-1)*20, 20, hql, time,null);
        return list3;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<Object> onetopic(PgcTopic pa) {//--查看显示单个话题详情  便于修改
		String hql="select a.id,a.user_id,a.title,a.content,a.image_url from pgc_topic as a where a.id=("+pa.getId()+")";
		return baseDao.lianhe(hql, null);
	}
	
	
	public Long topiccount(PgcTopic pt) {	//---查看显示话题的条数 马甲用户创建多少条数据
		String hql="select count(id) from PgcTopic where userId=("+pt.getUserId()+")";
		Long lo=baseDao.CountHql(hql);
		System.out.println("统计马甲用户创建话题条数为"+lo);
		return lo;
	}
	
	public Object oneinf(PgcTopic pa) {	//----返回单个 实体对象
		return baseDao.find(PgcTopic.class, pa.getId());
	}
	
	@SuppressWarnings("unchecked")
	public List<Object[]> alltopic() {
		String hql="select * from pgc_topic";
		return baseDao.Bysql(hql, PgcTopic.class);
	}
	
	
	public Long topiccount(Object obj,String time) {//--统计话题的评论个数
		String hql="select count(id) from UgcTopicJoin where toTopicId=("+obj+") and createTime>'("+time+")'";
		Long lo=baseDao.CountHql(hql);
		System.out.println(lo+"参与话题评论的个数");
		return lo;
	}
	
 }
